Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@koa/cors

Package Overview
Dependencies
Maintainers
8
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@koa/cors

Cross-Origin Resource Sharing(CORS) for koa

  • 2.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
553K
decreased by-23.85%
Maintainers
8
Weekly downloads
 
Created

What is @koa/cors?

@koa/cors is a middleware for Koa.js that enables Cross-Origin Resource Sharing (CORS) with various configuration options. It allows you to specify which origins are permitted to access your resources, as well as other CORS-related settings.

What are @koa/cors's main functionalities?

Basic CORS Setup

This code sets up a basic Koa server with CORS enabled for all origins. It uses the @koa/cors middleware without any additional configuration.

const Koa = require('koa');
const cors = require('@koa/cors');
const app = new Koa();
app.use(cors());
app.listen(3000);

Restricting Origins

This code configures the @koa/cors middleware to only allow requests from 'https://example.com'.

const Koa = require('koa');
const cors = require('@koa/cors');
const app = new Koa();
app.use(cors({ origin: 'https://example.com' }));
app.listen(3000);

Configuring Additional CORS Options

This code demonstrates how to configure additional CORS options such as allowed methods, headers, exposed headers, max age, and credentials.

const Koa = require('koa');
const cors = require('@koa/cors');
const app = new Koa();
app.use(cors({
  origin: '*',
  allowMethods: ['GET', 'POST'],
  allowHeaders: ['Content-Type', 'Authorization'],
  exposeHeaders: ['Content-Length', 'Date'],
  maxAge: 3600,
  credentials: true
}));
app.listen(3000);

Other packages similar to @koa/cors

Keywords

FAQs

Package last updated on 19 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc